package com.core.family.gen.service.gen.Impl.mysql;


import com.core.family.gen.domain.po.TableBeanPo;
import com.core.family.gen.domain.po.TableColumnPo;
import com.core.family.gen.service.gen.Impl.AbsGenHandler;

import java.sql.*;
import java.util.List;

/**
 * @description: mybatis 相关代码生成 通过链接器获取数据库元信息实现
 * @author: honglei
 * @time: 2021/3/23 0023 14:48
 */

public class GenMysqlHandlerV2 extends AbsGenHandler {


    @Override
    public List<TableBeanPo> tablesList() throws Exception {
        Connection connection = getConnection();
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        ResultSet rs = databaseMetaData.getTables(connection.getCatalog(), config.getUserName(),
                null, new String[]{"TABLE"});
        List<TableBeanPo> list = filledTableBean(rs);
        connection.close();
        return list;
    }


    @Override
    public List<TableColumnPo> getColumns(String table) throws Exception {
        Connection connection = getConnection();
        DatabaseMetaData databaseMetaData = connection.getMetaData();

        ResultSet resultSet = databaseMetaData.getColumns(null, "%", table, "%");

        List<TableColumnPo> list = filledTableColumn(resultSet);
        connection.close();
        return list;
    }


}
